<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>法援宝</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/lawyer.css" />
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../script/mobile.js"></script>
    <script type="text/javascript" src="../script/lawyer.js"></script>
</head>
<body>
<div id="secHeader">
  <header class="header">
      <!-- <a href="javascript:void(0);" onclick="api.closeWin()" class="back_btn"><img src="../image/head-fanhui.png" alt=""></a> -->
      <h2>登录</h2>
      <!-- <a href="javascript:void(0);" class="qiandao_btn" style="position: absolute;  right: 3%; top: 0; color: #fff;"><img src="../image/qiandao.png" onclick="aaplay('register')" >注册</a> -->
  </header>
</div>
<section class="login_section">
    <div class="fyb_logo"><img src="../image/fyb_logo.png" alt=""></div>
    <div class="login_box">
        <ul>
            <li class="username"><input type="text" placeholder="请输入手机号" id='phone' name='phone'></li>
            <li class="tel_code"><input type="text" placeholder="请输入验证码" id='yzm' name='yzm'><span id='regyzm'>获取验证码</span></li>
            <li class="user_code"><input type="text" placeholder="请输入推荐人邀请码(选填)" id='idno' name='idno'></li>
        </ul>
        <p class="agree">成功登陆APP即表示您同意<a href="##">《用户协议》</a></p>
        <button class="login_submit" type="submit" onclick="login()">立即登录</button>
        <p>如果该手机号为第一次登录，我们会直接为该 <br>手机号创建会员</p>
    </div>
</section>
<aside class="download showhide">
    <a href="##" class="user_download">普通用户点击下载【法援宝】</a>
</aside>


</body>

<script>
    apiready = function () {
      $api.fixStatusBar( $api.dom('#secHeader') );
      api.setStatusBarStyle({
          style: 'light'
      });
        

        $('#phone').val($api.getStorage ('phone'));

        apk()

    }
    function apk(){
        var p={id:32};
        api.ajax({
            url: webSiteUrl+'/app/public/ad',
            method: 'post',
            data: {

                values: p
            }
        }, function(ret, err) {


            if(ret.code==200){

                var tj=ret.data;
                if(tj != null){
                    $('.user_download').attr('href',webSiteUrl+tj.file);
                    $('.user_download').attr('download',webSiteUrl+tj.file);

                }
            }

        });

    }
    function showhide(){
        api.ajax({
            url: webSiteUrl+'/app/home/showhide',
            method: 'post',
            data: {


            }
        }, function(ret, err) {

            if(ret.code==200){

                $('.showhide').hide();

            }
        });

    }

    function login(){
        var phone=$("input[name=phone]").val();
        var yzm=$("input[name=yzm]").val();
        var idno=$("input[name=idno]").val();
        if(phone==''){
            api.alert({msg:"请输入手机号！"});return;
        }else if(!/^1[345678]\d{9}$/.test(phone)){
            api.alert({msg:"手机号格式错误！"});return;
        }/*else if(yzm==''){
            api.alert({msg:"请输入验证码！"});return;
        }*/

        var p={phone:phone,yzm:yzm,type:2};

        api.ajax({
            url: webSiteUrl+'/app/public/login',
            method: 'post',
            data: {

                values: p
            }
        }, function(ret, err) {
            if(ret.code==200){

                $api.clearStorage();
                $api.setStorage('user',ret.data);
                $api.setStorage('phone',phone);
                //alert(JSON.stringify(ret.data));


                api.openWin({
                    name: 'workbench',
                    url: './workbench.html',
                    reload: true,
                    pageParam: {
                        name: 'text'
                    }
                });

            }else{alert(ret.msg)}
        });

    }

    $('#regyzm').click(function () {
        if($(this).hasClass('regyzm')==false){
            var phone=$('input[name=phone]').val();
            if(phone==''){
                alert("请输入手机号！");return;
            }else if(!/^1[345678]\d{9}$/.test(phone)){
                alert("手机号格式错误！");return;
            }

            var p={phone:phone,type:2};
            api.ajax({
                url: webSiteUrl+'/app/public/yzm',
                method: 'post',
                data: {
                    values: p
                }
            }, function(ret, err) {
                if(ret.code==200){

                    $('#regyzm').addClass('regyzm');
                    var num=60;
                    timer=setInterval(function(){
                        $('#regyzm').html(num+'秒');
                        num--;
                        if(num==0){
                            clearInterval(timer);
                            timer=null;
                            $('#regyzm').html('重新获取');
                            $('#regyzm').removeClass('regyzm');
                        }
                    },1000)

                    alert(ret.msg)

                }else{alert(ret.msg)}
            });

        }
    })

</script>
</html>
